/**
 * Project: Useful Programs
 * Package: tools
 */
package org.leumasjaffe.collections;

import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
 * Class Swap in file Swap.java
 * 
 * @author leumasjaffe
 * Created on: Jul 26, 2012
 * 
 */
@NonNullByDefault
public final class Swap {
	
	/**
	 * 
	 */
	private Swap() {}
	
	/**
	 * @param array0
	 * @param index0
	 * @param index1
	 */
	public static <T> void swap(T[] array0, int index0, int index1) {
		swap(array0, index0, array0, index1);
	}
	
	/**
	 * @param list0
	 * @param index0
	 * @param index1
	 * 
	 * @deprecated Use {@link java.util.Collections#swap(List, int, int)} instead
	 */
	public static <T> void swap(List<T> list0, int index0, int index1) {
		swap(list0, index0, list0, index1);
	}
	
	/**
	 * @param array0
	 * @param index0
	 * @param array1
	 * @param index1
	 */
	public static <T> void swap(T[] array0, int index0, T[] array1, int index1) {
		T swap = array0[index0];
		array0[index0] = array1[index1];
		array1[index1] = swap;
	}
	
	/**
	 * @param list0
	 * @param index0
	 * @param list1
	 * @param index1
	 */
	public static <T> void swap(List<T> list0, int index0, List<T> list1, int index1) {
		T swap = list0.get(index0);
		list0.set(index0, list1.get(index1));
		list1.set(index1, swap);
	}
	
	/**
	 * @param array0
	 * @param index0
	 * @param index1
	 */
	public static void swap(int[] array0, int index0, int index1) {
		swap(array0, index0, array0, index1);
	}

	/**
	 * @param array0
	 * @param index0
	 * @param array1
	 * @param index1
	 */
	public static void swap(int[] array0, int index0, int[] array1, int index1) {
		int swap = array0[index0];
		array0[index0] = array1[index1];
		array1[index1] = swap;
	}
	
	/**
	 * @param array0
	 * @param index0
	 * @param index1
	 */
	public static void swap(double[] array0, int index0, int index1) {
		swap(array0, index0, array0, index1);
	}

	/**
	 * @param array0
	 * @param index0
	 * @param array1
	 * @param index1
	 */
	public static void swap(double[] array0, int index0, double[] array1, int index1) {
		double swap = array0[index0];
		array0[index0] = array1[index1];
		array1[index1] = swap;
	}
	
	/**
	 * @param array0
	 * @param index0
	 * @param index1
	 */
	public static void swap(float[] array0, int index0, int index1) {
		swap(array0, index0, array0, index1);
	}

	/**
	 * @param array0
	 * @param index0
	 * @param array1
	 * @param index1
	 */
	public static void swap(float[] array0, int index0, float[] array1, int index1) {
		float swap = array0[index0];
		array0[index0] = array1[index1];
		array1[index1] = swap;
	}

}
